#include "SplitSlaveData.h"
//#include <cstdio>

SplitSlaveData::SplitSlaveData()
{
	this->bSet	=	false;
	this->cMark	=	0;
	this->pCounts	=	NULL;
	this->pBounds	=	NULL;
	this->pPlots	=	NULL;
}

SplitSlaveData::~SplitSlaveData()
{
	this->bSet	=	false;
	this->cMark	=	0;
	delete	[]	this->pCounts;
	delete	[]	this->pBounds;
	delete	[]	this->pPlots;
}

void SplitSlaveData::load(int n, int cM)
{
    MPI_Status status;

	this->cMark = cM;
	this->pCounts = new int[this->cMark*3];
	MPI_Recv(this->pCounts, this->cMark*3, MPI_INT, n, 0, MPI_COMM_WORLD, &status );
	int ctri=0, cplo=0;
	int i=0;
	for(i=0; i<this->cMark;i++)
	{
		ctri+= this->pCounts[i];
		cplo+= this->pCounts[this->cMark+i];
	}
	this->pBounds	= new int[ctri*3];
	this->pPlots	= new float[cplo*3];
	MPI_Recv(this->pBounds, ctri*3, MPI_INT, n, 0, MPI_COMM_WORLD, &status );
	MPI_Recv(this->pPlots, cplo*3, MPI_FLOAT, n, 0, MPI_COMM_WORLD, &status );

//	printf("server: gettin %d %d\n", ctri, cplo);
}

void SplitSlaveData::getMarks(int &n, int *&pM)
{
	n = this->cMark;
	if(0==n)
		pM = NULL;
	else
		pM = this->pCounts; //+this->cMark*2;
}

void SplitSlaveData::getPlotsAndTriangs(int n, int &cp, float* &pP, int &ct, int* &pT)
{
	cp = this->pCounts[this->cMark*1+n];
	ct = this->pCounts[this->cMark*0+n];
	pP = this->pPlots;
	pT = this->pBounds;
	for(int i=0; i<n; i++)
	{
		pP += this->pCounts[this->cMark*1+i]*3;
		pT += this->pCounts[this->cMark*0+i]*3;
	}
}
